# -*- coding: utf-8 -*-
# 版权所有 (c) 华为技术有限公司 2023. All rights reserved.
# Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F


def gen_golden_data_simple():
    x_shape = (16384, 1024)
    eps = 1e-5
    dtype = torch.float32
    device = "cpu"
    x = torch.randn(*x_shape, dtype=dtype, device=device)
    gamma = nn.Parameter(torch.randn(x_shape[1], dtype=dtype, device=device))
    beta = nn.Parameter(torch.randn(x_shape[1], dtype=dtype, device=device))
    normalized_shape = (x_shape[-1],)
    res = F.layer_norm(x, normalized_shape, gamma, beta, eps)
    input_x = x.detach().numpy().astype(np.float32)
    input_gamma = gamma.detach().numpy().astype(np.float32)
    input_beta = beta.detach().numpy().astype(np.float32)
    layernorm_out = res.detach().numpy().astype(np.float32)
    softmax_out = np.argmax(layernorm_out, axis=1)
    golden = softmax_out.astype(np.uint32)

    input_x.tofile("./input/input_x.bin")
    input_gamma.tofile("./input/input_gamma.bin")
    input_beta.tofile("./input/input_beta.bin")
    golden.tofile("./output/golden.bin")


if __name__ == "__main__":
    gen_golden_data_simple()
